package com.cnpc.rightslogan.service.impl;

import com.cnpc.rightslogan.entity.Organization;
import com.cnpc.rightslogan.mapper.OrganizationMapper;
import com.cnpc.rightslogan.service.IOrganizationService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class OrganizationServiceImpl implements IOrganizationService {

    @Resource
    private OrganizationMapper organizationMapper;

    @Override
    public Organization getOrganization(int id) {
        Organization organization = new Organization();
        organization.setOrgId(id);
        return organizationMapper.selectOne(organization);
    }

    @Override
    public Organization getOrganization(Organization organization) {
        return organizationMapper.selectOne(organization);
    }

    @Override
    public PageInfo<Organization> getOrganizationList(Integer pageNum, Integer pageSize, Organization organization) {
        PageHelper.startPage(pageNum, pageSize);
        List<Organization> organizationList = organizationMapper.select(organization);
        return new PageInfo<>(organizationList);
    }

    @Override
    public Integer addOrganization(Organization organization) {
        return organizationMapper.insert(organization);
    }

    @Override
    public Integer updateOrganization(Organization organization) {
        return organizationMapper.updateByPrimaryKeySelective(organization);
    }

    @Override
    public Integer deleteOrganization(Organization organization) {
        return organizationMapper.delete(organization);
    }
}